package cn.stylefeng.guns.sys.modular.metadataCol.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.metadataCol.entity.MetadataCol;
import cn.stylefeng.guns.sys.modular.metadataCol.model.params.MetadataColParam;
import cn.stylefeng.guns.sys.modular.metadataCol.service.MetadataColService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 数据元表控制器
 *
 * @author author
 * @Date 2020-11-19 13:41:04
 */
@Controller
@RequestMapping("/metadataCol")
public class MetadataColController extends BaseController {

    private String PREFIX = "/modular/metadataCol/metadataCol";

    @Autowired
    private MetadataColService metadataColService;

    /**
     * 跳转到主页面
     *
     * @author author
     * @Date 2020-11-19
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/metadataCol.html";
    }

    /**
     * 新增页面
     *
     * @author author
     * @Date 2020-11-19
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/metadataCol_add.html";
    }

    /**
     * 编辑页面
     *
     * @author author
     * @Date 2020-11-19
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/metadataCol_edit.html";
    }

    /**
     * 新增接口
     *
     * @author author
     * @Date 2020-11-19
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(MetadataColParam metadataColParam) {
        this.metadataColService.add(metadataColParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author author
     * @Date 2020-11-19
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(MetadataColParam metadataColParam) {
        this.metadataColService.update(metadataColParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author author
     * @Date 2020-11-19
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(MetadataColParam metadataColParam) {
        this.metadataColService.delete(metadataColParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author author
     * @Date 2020-11-19
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(MetadataColParam metadataColParam) {
        MetadataCol detail = this.metadataColService.getById(metadataColParam.getMetadataColId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author author
     * @Date 2020-11-19
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(MetadataColParam metadataColParam) {
        return this.metadataColService.findPageBySpec(metadataColParam);
    }


    /**
     * 逻辑删除
     *
     * @param arr
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteMetadataDetail")
    public int deleteMetadataDetailById(@RequestParam String[] arr) {
        int number = 0;
        for (int i = 0; i < arr.length; i++) {
            this.metadataColService.deleteMetadataDetailInfo(arr[i]);
            number++;
        }
        return number;
    }

}


